<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://mail">

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	
	
	<xsl:include href="../main.xsl" />
	<xsl:include href="../menu.xsl" />
	<xsl:include href="../common/navigation.xsl" />

	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<script type="text/javascript" src="{$baseURI}/js/mail.js" />
			<link rel="stylesheet" href="{$baseURI}/css/mail.css" type="text/css" media="all" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />

			<div id="header">
				<xsl:call-template name="logo" />

				<xsl:call-template name="menu" />
			</div>

			<div id="blocks">
				<div id="blocks_inner">
					<xsl:call-template name="default-blocks-top" />
				</div>
			</div>

			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>

			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	
	<xsl:template match="response">
		<h1>&labelMail; (<a href="{$baseURI}/mail/write">&labelWrite;</a>)</h1>
		
		<xsl:if test="count(object) = 0">
			<p>&labelMailEmpty;</p>
		</xsl:if>
		
		<xsl:if test="count(object) != 0">
			<form action="{$baseURI}/mail/delete" method="post" id="form_delete_mail">		
				<table id="mail_list" cellspacing="0" cellpadding="0">
					<xsl:apply-templates select="object" />
				</table>
				<p>
					<input onclick="deleteFormConfirm(); return false;" type="submit" value="&labelDeleteSelected;" />
				</p>
			</form>
		</xsl:if>
		
		<xsl:apply-templates select="pages" mode="pages-navigation">
			<xsl:with-param name="href">
				<xsl:value-of select="$baseURI" />
				<xsl:text>/mail</xsl:text>
			</xsl:with-param>
		</xsl:apply-templates>
	</xsl:template>
	
	<xsl:template match="object[@type='message']">
		<xsl:param name="senderLogin" select="property[@name='sender_login']/value" />
		<xsl:param name="addressedLogin" select="property[@name='addressed_login']/value" />
		
		<tr>
			<xsl:if test="@read = '0'">
				<xsl:attribute name="class">new</xsl:attribute>
			</xsl:if>
			<td class="delete_message">
				<input type="checkbox" name="delete[{@type-id}][]" value="{@id}" />
			</td>
			<td class="sender">
				<xsl:choose>
					<xsl:when test="property[@name='sender_id']/value = $userId">
						<xsl:text>&labelImBig; → </xsl:text>
						<a href="{$baseURI}/user/{$addressedLogin}">
							<xsl:value-of select="property[@name='addressed_name']/value" />
						</a>
					</xsl:when>
					<xsl:otherwise>
						<a href="{$baseURI}/user/{$senderLogin}">
							<xsl:value-of select="property[@name='sender_name']/value" />
						</a>
						<xsl:text> → &labelIm;</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</td>
			<td class="subject">
				<a href="{$baseURI}/mail/read/{@type}/{@id}">
					<xsl:value-of select="property[@name='subject']/value" />
				</a>
				<xsl:if test="number(property[@name='count_comments']/value) &gt; 0">
					<xsl:text disable-output-escaping="yes">&amp;nbsp;&amp;nbsp;&amp;nbsp;</xsl:text>
					<xsl:value-of select="property[@name='count_comments']/value" />
				</xsl:if>
			</td>
			<td class="date">
				<xsl:if test="position() = 1">
					<span>&labelLastReply;: </span>
				</xsl:if>
				<xsl:value-of select="property[@name='date']/value" />
			</td>
		</tr>
	</xsl:template>
	
	<xsl:template match="object[@type='system_notification']">
		<tr>
			<xsl:if test="@read = '0'">
				<xsl:attribute name="class">new</xsl:attribute>
			</xsl:if>
			<td class="delete_message">
				<input type="checkbox" name="delete[{@type-id}][]" value="{@id}" />
			</td>
			<td class="sender">
				<xsl:text>&labelNotification;</xsl:text>
			</td>
			<td class="subject">
				<a href="{$baseURI}/mail/read/{@type}/{@id}">
					<xsl:value-of select="property[@name='subject']/value" />
				</a>
			</td>
			<td class="date">
				<xsl:if test="position() = 1">
					<span>&labelDate;: </span>
				</xsl:if>
				<xsl:value-of select="property[@name='date']/value" />
			</td>
		</tr>
	</xsl:template>
	
</xsl:stylesheet>